package com.aidex.common.utils.sms;


import com.jdcloud.sdk.auth.CredentialsProvider;
import com.jdcloud.sdk.auth.StaticCredentialsProvider;
import com.jdcloud.sdk.http.HttpRequestConfig;
import com.jdcloud.sdk.http.Protocol;
import com.jdcloud.sdk.service.sms.client.SmsClient;
import com.jdcloud.sdk.service.sms.model.*;

import java.util.ArrayList;
import java.util.List;

public class JdSmsClient {
    private static SmsClient smsClient;
    // 地域信息不用修改
    private static String region = "cn-north-1";

    //信利典当短信验证码初始化方法
    public static void init() {
        // 请填写AccessKey ID
        String accessKeyId = "JDC_38CFDD5D635A4903A76C66D79944";
        // 请填写AccessKey Secret
        String secretAccessKey = "25DA5E57FB1B23A55708D17329F4F65A";
        CredentialsProvider credentialsProvider = new StaticCredentialsProvider(accessKeyId, secretAccessKey);
        smsClient = SmsClient.builder()
                .credentialsProvider(credentialsProvider)
                .httpRequestConfig(new HttpRequestConfig.Builder().protocol(Protocol.HTTP).build()) //默认为HTTPS
                .build();
    }

    /**
     * 信利典当指定模板发送短信验证码
     */
    public static void sendCodeMsg(String phone,String code) {
        BatchSendRequest request = new BatchSendRequest();
        request.setRegionId(region);
        // 设置模板ID 应用管理-文本短信-短信模板 页面可以查看模板ID
        request.setTemplateId("mb_491f33a6d201422f978ba34a415a97eb");
        // 设置签名ID 应用管理-文本短信-短信签名 页面可以查看签名ID
        request.setSignId("qm_e5812e5ab0114b85baf13f24622f98de");
        // 设置下发手机号list
        List<String> phoneList = new ArrayList<>();
        phoneList.add(phone);
        request.setPhoneList(phoneList);
        // 设置模板参数，非必传，如果模板中包含变量请填写对应参数，否则变量信息将不做替换。
        List<String> params = new ArrayList<>();
        params.add(code);
        request.setParams(params);
        BatchSendResponse response = smsClient.batchSend(request);

    }

    /**
     * 信利典当指定模板发送短信通知
     */
    public static BatchSendResponse sendNotice(String phone) {
        BatchSendRequest request = new BatchSendRequest();
        request.setRegionId(region);
        // 设置模板ID 应用管理-文本短信-短信模板 页面可以查看模板ID
        request.setTemplateId("mb_19d0ed357c964e5399e89f74872f7471");
        // 设置签名ID 应用管理-文本短信-短信签名 页面可以查看签名ID
        request.setSignId("qm_e5812e5ab0114b85baf13f24622f98de");
        // 设置下发手机号list
        List<String> phoneList = new ArrayList<>();
        phoneList.add(phone);
        request.setPhoneList(phoneList);
        return smsClient.batchSend(request);
    }
}
